<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>资源详情</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui2/aui.css" />
	<style>
	    body {}
	    .hidden{
	       display: none !important;
	    }
	</style>
</head>
<body>
	<header class="aui-bar aui-bar-nav aui-bar-primary">
        <div class="aui-pull-left aui-btn" id="btn_return" onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>返回
        </div>
        <div class="aui-title"></div>
        <div id="pushbtn" tapmode class="aui-pull-right aui-btn aui-btn-outlined hidden" onclick="pushCourse();">
            推送
        </div>
    </header>
</body>
<script data-main="../../script/main" src="../../script/require.js"></script>
<script type="text/javascript">
	apiready = function(){
		require(["zepto","api","common"],function(){
			var header = $api.dom('header');
			$api.fixStatusBar(header);
			var headerPos = $api.offset(header);
			api.pageParam.headerPos = headerPos;
			checkAuth();
			studylog();
			
			api.addEventListener({
	            name:'keyback'
            },function(ret,err){
                api.setScreenOrientation({
	                orientation:'portrait_up'
                });
            	closeWin();
            });
            if(api.pageParam.data.charge_status=="3"){
                $(".aui-title").html("学习课程");
                api.openFrame({
	                name: 'rs_unpaid',
	                url: './rs_unpaid.html',
	                rect: {
                        x:0,
                        y:0,
                        w:headerPos.w,
                        h:'auto',
                        marginTop:headerPos.h
                    },
	                pageParam:api.pageParam,
                    slidBackEnabled:false
                });
                return;
            }
			switch(api.pageParam.index){
			case 1:
				$(".aui-title").html("微课");
				api.openFrame({
                    name: 'rs_microclass',
                    url: './rs_microclass.html',
                    rect: {
	                    x:0,
	                    y:0,
	                    w:headerPos.w,
	                    h:'auto',
	                    marginTop:headerPos.h
                    },
                    pageParam:api.pageParam.data,
                    slidBackEnabled:false
                });
				break;
			case 2:
				$(".aui-title").html("直播");
				api.openFrame({
                    name: 'rs_paid',
                    url: './rs_paid.html',
                    rect: {
	                    x:0,
	                    y:0,
	                    w:headerPos.w,
	                    h:'auto',
	                    marginTop:headerPos.h
                    },
                    pageParam:api.pageParam,
                    slidBackEnabled:false
                });
				break;
			case 3:
				$(".aui-title").html("试卷");
				api.openFrame({
                    name: 'rs_test',
                    url: './rs_test.html',
                    rect: {
                        x:0,
                        y:0,
                        w:headerPos.w,
                        h:'auto',
                        marginTop:headerPos.h
                    },
                    pageParam:api.pageParam,
                    slidBackEnabled:false
                });
				break;
			case 4:
				$(".aui-title").html("讨论");
				api.openFrame({
                    name: 'rs_discussion',
                    url: './rs_discussion.html',
                    rect: {
                        x:0,
                        y:0,
                        w:headerPos.w,
                        h:api.winHeight-100,
                        marginTop:headerPos.h
                    },
                    pageParam:api.pageParam,
                    slidBackEnabled:false
                });
				break;
			}
		})
	};
	
	function checkAuth(){
	   $zb.prefs.getPrefs('userInfo',function(ret){
	       var usertype = JSON.parse(ret.value).usertype;
	       if(usertype==$zb.usertype.USERTYPE_STUDENT){
	           $("#pushbtn").addClass('hidden');
	       }else{
	           $("#pushbtn").removeClass('hidden');
	       }
	   })
	}
	
	function studylog(){
	    $zb.prefs.getPrefs('token',function(ret){
            var token = ret.value;
            var s_data = {
                values:{
                    token : token,
                    course_id : api.pageParam.info.id
                }
            }
            $zb.requestForData(s_data,'resources','logStudy',function(ret){
                console.log(JSON.stringify(ret));
            });
        })
	}
	
	function pushCourse(){
        api.openWin({
	        name: 'pushcourse_win',
	        url: './pushcourse_win.html',
	        pageParam:api.pageParam
        });
	}
	
	function disConnect(){
		var rong = api.require('rongCloud2');
		rong.disconnect({
		    isReceivePush: true
		},function(ret,err){
			console.log(JSON.stringify(ret));
		});
	}
	
	function closeWin(){
        if(api.pageParam.index==2){
            disConnect();
        }
		api.closeWin();
	}
</script>
</html>